import { request } from './request'
import { popup } from './tools'
import { getJMByBillNum } from './common'
import config from './config'
import store from '@/store'
/**
 * 废弃单据
 * @param {*} number 单据号码
 * @param {*} cb 回调
 */
export function abandonNewBills (number, cb) {
  popup({
    tpl: 'alert',
    title: '提示',
    content: '您确定要废弃当前单据吗？',
    buttons: ['取消', `<div class="tc-main">确定</div>`],
    buttonCallBack: index => {
      if (index === 1) {
        let type = getJMByBillNum(number)
        let method = 'abandonNewBills'
        let data = {
          method,
          number,
          type
        }
        if (type === 'CS') {
          data = {
            method: 'abandonBills',
            billNum: number
          }
        }
        request({
          url: config.api.host,
          data
        }).then(res => {
          if (res.code === 200) {
            popup({
              tpl: 'alert',
              title: '提示',
              content: '废弃成功',
              buttons: [`<div class="tc-main">确定</div>`],
              buttonCallBack: index => {
                if (cb) cb()
              }
            })
          }
        })
      }
    }
  })
}
/**
 * 获取额度
 */
export function getBudgetDo (cb) {
  request({
    url: config.api.host,
    data: {
      method: 'getBudgetDo',
      userNum: store.state.userNum,
      companyNum: store.state.userInfo.companyNum
    }
  }).then(res => {
    if (res.code === 200) {
      if (cb) cb(res.t)
      // this.formatChartData(res.t)
    }
  })
}
/**
 *获取城市列表
 *
 * @export
 */
export function getCitys (cb) {
  request({
    url: config.api.host,
    data: {
      method: 'getCitys'
    }
  }).then(res => {
    if (res.code === 200) {
      if (cb) cb(res.t)
    }
  })
}
/**
 * 获取出差申请单列表
 * @param {*} requestData
 * @param {*} cb
 */
export function getEvectionReqBills (requestData, cb) {
  request({
    url: config.api.host,
    data: {
      method: 'getEvectionReqBills',
      ...requestData
    }
  }).then(res => {
    if (res.code === 200) {
      if (cb) cb(res.t)
    }
  })
}
// 出差标准
export function getTravelTripStandards (requestData, cb) {
  request({
    url: config.api.host,
    data: {
      method: 'getTravelTripStandards',
      ...requestData
    }
  }).then(res => {
    if (res.code === 200) {
      if (cb) cb(res.t[0])
    }
  })
}
